/**
 * @Company 航天科技山西公司
 * @Project hitech-WORKFLOW-Web
 * @Package com.hitech.web.workflow
 * @Title ActModelController.java
 * @Description TODO(描述)
 * @author 颜金星
 * @create 2017年4月21日-下午2:52:29
 * @version V 1.0
 */
package com.casic.modules.activiti.controller;

import com.casic.common.utils.PageUtils;
import com.casic.common.utils.R;
import com.casic.modules.activiti.entity.Task;
import com.casic.modules.activiti.service.ActTaskService;
import com.casic.modules.activiti.util.JqGridPageView;
import com.casic.modules.activiti.util.WebUtil;
import com.casic.modules.activiti.vo.ModelVo;
import com.casic.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @Company 航天科技山西公司
 * @Project hitech-WORKFLOW-Web
 * @Package com.hitech.web.workflow
 * @ClassName ActModelController.java
 * @Description TODO(工作流TASK控制类)
 * @author 颜金星
 * @create 2017年4月21日-下午2:52:29
 */
@RestController
@Api(value = "待办任务", description = "待办任务")
@RequestMapping(value = "/workflow/actTask", method = RequestMethod.POST)
public class ActTaskController extends AbstractController {
      
	  @Autowired
	  private ActTaskService actTaskService;
	  /**
	   * 
	   * @Title getActModelList
	   * @Description (流程模型列表)
	   * @author 颜金星
	   * @create 2017年4月21日-下午5:18:10
	   * @Param @param request
	   * @Param @param modelMap
	   * @Param @param response
	   * @Param @return
	   * @return Object
	   * @throws
	   */
	  @ApiOperation(value = "待办事项列表")
	  //@RequiresPermissions("sys.dept.read")
      @RequestMapping(value = "/getTaskList",method = RequestMethod.GET)
	  public R getTaskList(HttpServletRequest request, ModelMap modelMap, HttpServletResponse response) {
		  Map<String, Object> params = WebUtil.getParameterMap(request);
		  int firstResult = 1;
		  int maxResults = 10;
		  if(params.get("page")!=null){
			  firstResult=Integer.parseInt((String)params.get("page"));
		  }
		  if(params.get("limit")!=null){
			  maxResults = Integer.parseInt((String)params.get("limit"));
		  }
		  if(!params.containsKey("rows")){
			  params.put("rows",Integer.parseInt((String)params.get("limit")));
		  }
		  JqGridPageView<Task> page=actTaskService.getTaskList(params);
		  int pagetotal=(int)page.getRecords();

		  PageUtils pageUtil = new PageUtils(page.getRows(), pagetotal, maxResults, Integer.parseInt(params.get("page")+""));

		  return R.ok().put("page", pageUtil);
	  }
	  /**
	   * 
	   * @Title claim
	   * @Description (任务签收)
	   * @author 颜金星
	   * @create 2017年5月15日-下午2:11:01
	   * @Param @param request
	   * @Param @param modelMap
	   * @Param @param response
	   * @Param @return
	   * @return Object
	   * @throws
	   */
	  @ApiOperation(value = "签收任务")
	  //@RequiresPermissions("sys.dept.read")
      @RequestMapping(value = "/claim")
	  public R claim(HttpServletRequest request, ModelMap modelMap, HttpServletResponse response) {
		    Map<String, Object> params = WebUtil.getParameterMap(request);
		    actTaskService.claim(params);
		  return R.ok();
	  }
	  /**
	   * 
	   * @Title getTaskForm
	   * @Description (获取Task表单结构数据)
	   * @author 颜金星
	   * @create 2017年5月15日-下午2:22:29
	   * @Param @param request
	   * @Param @param modelMap
	   * @Param @param response
	   * @Param @return
	   * @return Object
	   * @throws
	   */
	  @ApiOperation(value = "获取Task表单结构数据")
	  //@RequiresPermissions("sys.dept.read")
      @RequestMapping(value = "/getTaskForm")
	  public R getTaskForm(HttpServletRequest request, ModelMap modelMap, HttpServletResponse response) {
		    Map<String, Object> params = WebUtil.getParameterMap(request);
		    Map<String, Object> data=actTaskService.getTaskForm(params);
		  return R.ok(data);
	  }
	  /**
	   * 
	   * @Title complete
	   * @Description (办理任务流程)
	   * @author 颜金星
	   * @create 2017年5月15日-下午2:42:41
	   * @Param @param request
	   * @Param @param modelMap
	   * @Param @param response
	   * @Param @return
	   * @return Object
	   * @throws
	   */
	  @ApiOperation(value = "办理流程任务")
	  //@RequiresPermissions("sys.dept.read")
      @RequestMapping(value = "/complete")
	  public R complete(HttpServletRequest request, ModelMap modelMap, HttpServletResponse response) {

		  Map<String, Object> params = WebUtil.getParameterMap(request);
		  actTaskService.complete(params, request);
		  return R.ok();
	  }
}
